* Program to compute ASL of difference of means using naive moving block bootstrap
* and dummy-variable regressions with HAC-corrected standard errors
* for statistical detrending procedures showing consistent improvement.

* This program: Uses 1966-1997 vs. 1998-2006 sample, standard deviation-based NSRs
* and looks at Baxter-King gaps


calendar 1947 1 4
allocate 2020:04+5000


open data table2_reg_test_data.rat
data(format=rats) / bk_revgapvr_f32 bk_revgapvr_f09


set bk_revgapvr 1966:01 1997:04 = bk_revgapvr_f32
set bk_revgapvr 1998:01 2006:04 = bk_revgapvr_f09


seed 43892



* Set bootstrap and related parameters

compute ndraws=5000
compute nblocks=4
compute haclags=4
set t_ovn_stddev = %NA


set dum98q1 = 0.0
set dum98q1 1998:01 2006:04 = 1.0

linreg(robusterrors,lags=haclags,lwindow=neweywest) bk_revgapvr
# constant dum98q1


statistics(noprint) bk_revgapvr 1966:01 1997:04
compute mean1=%mean
statistics(noprint) bk_revgapvr 1998:01 2006:04
compute mean2=%mean
statistics(noprint) bk_revgapvr 1966:01 2006:04
compute meanfull=%mean

disp "Difference in means = " mean2-mean1


set zzz 1966:01 1997:04 = bk_revgapvr-mean1+meanfull
set yyy 1998:01 2006:04 = bk_revgapvr-mean2+meanfull


do iter=1,ndraws

  set b_zzz = %NA
  set b_yyy = %NA

  boot(replace,block=nblocks,method=overlap) b_entry1 1966:01 1997:04
  set b_zzz = zzz(b_entry1)

  boot(replace,block=nblocks,method=overlap) b_entry2 1998:01 2006:04
  set b_yyy = yyy(b_entry2)

  linreg(robusterrors,lags=haclags,lwindow=neweywest,noprint) b_zzz
  # constant
  compute mean_bzzz=%beta(1)
  compute se_bzzz=%stderrs(1)

  linreg(robusterrors,lags=haclags,lwindow=neweywest,noprint) b_yyy
  # constant
  compute mean_byyy=%beta(1)
  compute se_byyy=%stderrs(1)

  set t_ovn_stddev iter iter = (mean_byyy-mean_bzzz)/sqrt((se_bzzz**2.0)+(se_byyy**2.0))


end do iter


statistics(fract) t_ovn_stddev


